package com.teamwings.modules.code.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.teamwings.modules.code.entity.FormTableCode;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author admin
 * @since 2021-05-06
 */
@Repository
public interface FormTableCodeMapper extends BaseMapper<FormTableCode> {

    FormTableCode getLatestOneByFormId(@Param("formId") String formId);

    List<FormTableCode> getLatestListByFormIds(@Param("headIds") List<String> headIds);

    @Results({@Result(column = "TABLE_HEAD_ID",property = "head",
        one = @One(select = "com.teamwings.modules.head.mapper.FormTableHeadMapper.selectById"))})
    @Select("select * from FORM_TABLE_CODE ${ew.customSqlSegment} ")
    List<FormTableCode> getCodeWithHead(@Param(Constants.WRAPPER)Wrapper<FormTableCode> wrapper);

    @Select("select TABLE_CODE from " +
        " FORM_TABLE_CODE c join FORM_TABLE_HEAD h " +
        " ON c.TABLE_HEAD_ID  = h.ID  " +
        " ${ew.customSqlSegment} and h.TABLE_VERSION = c.TABLE_VERSION ")
    List<String> getTableCodeWithHeads(@Param(Constants.WRAPPER)Wrapper<FormTableCode> wrapper);



}
